package com.example.mybatisdemo.Controller;

import com.example.mybatisdemo.Service.UserService;
import com.example.mybatisdemo.model.User;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 666
 * Date: 2023-08-11
 * Time: 17:56
 */
@RestController
@RequestMapping("/u")
public class UserController {
    @Resource
    private UserService userService;
    @RequestMapping("/getall")
    public List<User> getAll(){
        return userService.getAll();
    }
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Integer add(@RequestBody User user){
        userService.add(user);
        return user.getId();
    }
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Integer update( Integer id,  String name) {
        return userService.update(id, name);
    }
    @RequestMapping("/delById")
    public Integer delById( Integer id){
        return userService.delById(id);
    }
    @RequestMapping("/id")
    public  User getUserById(Integer id){
        return userService.getUserById(id);
    }
    @RequestMapping("/insert")
    public Integer insert(User user){
        return  userService.insert(user);
    }
    @RequestMapping("selectByCondition")
    public List<User> selectByCondition(User user){
        return userService.selectByCondition(user);
    }
    @RequestMapping("updateById")
    int updateById(User user){
        return userService.updateById(user);
    }
   @RequestMapping("/deleteByIds")
    public int deleteByIds(@RequestParam("ids") List<Integer> ids){
        return userService.deleteByIds(ids);
   }
}
